﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace HRM.Upgrade.Common
{
    public class Execute : BaseDAO
    {
        public Execute(string cn)
        {
            ConnectionString = cn;
        }

        public int CustomerInsert(string nameCompany, string address,
                                        string tell, string mobile, string fax, string web,
                                        string email, string taxId, string busLic, string contactMan
                                        , string pos)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@NameCompany", SqlDbType.NVarChar, nameCompany),
                        CreateParameter("@Address", SqlDbType.NVarChar, address),
                        CreateParameter("@Tell", SqlDbType.VarChar, tell),
                        CreateParameter("@Mobile", SqlDbType.NVarChar, mobile),
                        CreateParameter("@Fax", SqlDbType.VarChar, fax),
                        CreateParameter("@Website", SqlDbType.VarChar, web),
                        CreateParameter("@Email", SqlDbType.VarChar, email),
                        CreateParameter("@TaxID", SqlDbType.VarChar, taxId),
                        CreateParameter("@BusinessLicense", SqlDbType.VarChar, busLic),
                        CreateParameter("@ContactMan", SqlDbType.NVarChar, contactMan),
                        CreateParameter("@Contents", SqlDbType.NText, "MD"),
                        CreateParameter("@Active", SqlDbType.Bit, true),
                        CreateParameter("@Notes", SqlDbType.NText, "MD"),
                        CreateParameter("@ContactMan_A", SqlDbType.NVarChar, contactMan),
                        CreateParameter("@Position", SqlDbType.NVarChar, pos),
                        CreateParameter("@Typical", SqlDbType.Bit, false),
                        CreateParameter("@Collocation", SqlDbType.Int, "0"),
                    };

                return ExecuteNonQueryProcedure(Constants.StoredProcedure.Customer_Insert, parameters);

            }
            catch (Exception)
            {
                return -1;
            }

        }

        public int KeyCodeInsert(string keyCode, int idSoft, int idContact, int numActive, int actived)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@KeyCode", SqlDbType.VarChar, keyCode),
                        CreateParameter("@Id_Soft", SqlDbType.Int, idSoft),
                        CreateParameter("@Id_Contact", SqlDbType.Int, idContact),
                        CreateParameter("@DateCreate", SqlDbType.DateTime, DateTime.Now),
                        CreateParameter("@Property", SqlDbType.NVarChar, "MD"),
                        CreateParameter("@NumActive", SqlDbType.Int, numActive),
                        CreateParameter("@Activated", SqlDbType.Int, actived),
                        CreateParameter("@Blacklist", SqlDbType.Bit, false),
                        CreateParameter("@TypeActive", SqlDbType.Int, 1),
                        CreateParameter("@TypeSoft", SqlDbType.Int, 6),
                        CreateParameter("@DateLimit", SqlDbType.DateTime, DateTime.Now.AddYears(100)),
                        CreateParameter("@Register", SqlDbType.Bit, true),
                        CreateParameter("@Technical_Staff", SqlDbType.Int, 1),
                        CreateParameter("@Sales_Staff", SqlDbType.Int, 1),
                        CreateParameter("@Money", SqlDbType.Int, 100),
                        CreateParameter("@Payment", SqlDbType.Int, 100),
                        CreateParameter("@DatePayment", SqlDbType.DateTime, DateTime.Now),
                        CreateParameter("@TypePayment", SqlDbType.NVarChar, "MD"),
                        CreateParameter("@Notes", SqlDbType.NVarChar, "MD"),
                        CreateParameter("@Id_Contract", SqlDbType.Int, 1),
                        CreateParameter("@Number", SqlDbType.Int, 100),
                    };

                return ExecuteNonQueryProcedure(Constants.StoredProcedure.Keycode_Insert, parameters);

            }
            catch (Exception)
            {
                return -1;
            }

        }

    }
}
